package Schema::Result::Company;

use strict;
use warnings;
use utf8;

use base qw/DBIx::Class::Core/;

__PACKAGE__->table('Company');
__PACKAGE__->add_columns(
    Id => {data_type => 'integer', is_auto_increment => 1}, 
    Name => {}, 
    Comment => {},
);
__PACKAGE__->set_primary_key('Id');
__PACKAGE__->has_many(Projects => 'Schema::Result::Project', 'CompanyId', { cascade_delete => 1 });

# 创建组织
sub Create{
    my ($class, $schema, $params) = @_;

    my $newCompany = $schema->resultset('Company')->create($params);

    return $newCompany;
}

# 修改组织信息
sub Modify {
    my ($self, $name, $comment) = @_;
    if(defined $name){
        $self->Name($name);
    }
    if(defined $comment) {
        $self->Comment($comment);
    }

    $self->update;
}

# 删除
sub Delete {
    my ($self) = @_;

    $self->delete;
}

1;
